/**
 * @(#) CongMoneyMediator.as
 *
 * @date		2009. 03. 25.
 * @version		1.0
 * @author		baek, kwang hyoun
 * @description	건강보험증 신청 - Mediator
 * 				건강보험증을 조회하고 신청하는 Presentation Logic을 관리
 */
package com.skt.common_hr.retirement.view
{
	import com.skt.common_hr.common.approval.RequestApprovalMediator;
	import com.skt.common_hr.common.memberselector.MemberSelectorMediator;
	import com.skt.common_hr.common.puremvc.OverViewMediator;
	import com.skt.common_hr.retirement.view.components.RetirementOverView;
	import com.wcl.utils.DateUtil;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.multicore.interfaces.INotification;

	public class RetirementMediator extends OverViewMediator
	{
		public static const NAME:String = "RetirementMediator";


		/**
		* 생성자
		*
		* @param
		* @return void
		*/
        public function RetirementMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
        }

		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		* 최초 한번만 불림
		*/
 		override protected function initializeView():void
 		{
			super.initializeView();
 		}
		/***
		 * 활성화가 될때마다 불림.
		 */
		override protected function activatedView():void
		{
			super.activatedView();
			view.clearView();
 			loadList();
			setEventListener();
		}

		override protected function closedView():void
		{
			removeEventListener();
		}

 		private function setEventListener():void
 		{
 			view.addEventListener("TEST", onAddMember);
 			
 		}

		private function onAddMember(event:Event):void
		{
			var mediator:MemberSelectorMediator;
			mediator = facade.retrieveMediator(MemberSelectorMediator.NAME) as MemberSelectorMediator;
			if(mediator==null) {
				mediator = new MemberSelectorMediator();
				facade.registerMediator(mediator);
			}
			mediator.exec(view.root);
		}


 		private function removeEventListener():void
 		{
			//view.removeEventListener(HthIcFacade.HthIcWrite, onClickNew);
 		}


 		private function loadList():void
 		{
 			view.loadMainList();
// 			var mProxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
//			mProxy.loadList(Variables.myPernr);
 		}


		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		*
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array
		{
			return basicInterestMessages.concat([
					MemberSelectorMediator.SELECTED_MEMBER,
					RequestApprovalMediator.APPROVAL_CANCEL,
					RequestApprovalMediator.APPROVAL_COMPLETE
					// reload
//					ReqMedicalMoneyMediator.CLOSED_REQUEST_VIEW,
//					MedicalMoneyProxy.LOAD_MEDICALMONEY_LIST_COMPLETE,
//					MedicalMoneyProxy.LOAD_MEDICALMONEY_LIST_FAILED
					]);
		}


		/**
		* Noti별로 처리한다.
		*
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			super.handleNotification(note);
			switch(note.getName())
			{
				case MemberSelectorMediator.SELECTED_MEMBER:
				//case BizTripFacade.SELECTED_MEMBER:
						var selectedPernr:String = MemberSelectorMediator(note.getBody()).selectedMember.PERNR;
						var selectedEname:String = MemberSelectorMediator(note.getBody()).selectedMember.ENAME;
					break;


				case RequestApprovalMediator.APPROVAL_COMPLETE:					// 결재 요청  성공
					view.loadMainList();
					//Alert.show('신청되었습니다.');

					break;
				case RequestApprovalMediator.APPROVAL_CANCEL:					// 결재 요청 취소
					break;



				// 의료비 리스트  조회 Proxy 호출결과 처리
//				case MedicalMoneyProxy.LOAD_MEDICALMONEY_LIST_COMPLETE :
//					setListView(MedicalMoneyProxy(note.getBody()).mainList);
//					break;
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}

 		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - load된 데이터를 화면에 출력
		 * @param
		 * @return void
		 */
 		private function setListView(list:ArrayCollection):void
 		{
// 			view.medicalMoneyDataList = list;
// 			commonFacade.setStatusMessage("STATUS_LOADED_LIST", [list.length.toString()]);
// 			if(list.length == 0) {
// 				view.showInitialTip();
// 			}
 		}


		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
       private function get view():RetirementOverView
        {
            return viewComponent as RetirementOverView;
        }


	}
}